package org.itboys.core.controller.web;

import org.itboys.commons.CommonConstants;
import org.itboys.commons.dto.ResultPageDOHelper;
import org.itboys.commons.utils.ajax.AjaxUtils;
import org.itboys.core.entity.mysql.SundaySkuPrice;
import org.itboys.core.service.mysql.web.SundaySkuPriceService;
import org.itboys.framework.query.JsonPageUtils;
import org.itboys.framework.spring.controller.BaseController;
import org.itboys.param.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 作者：zzq
 * 时间：2018/8/17
 * 描述：
 */
@Controller
@RequestMapping("/sunday/web/sku/price")
public class SundaySkuPriceController extends BaseController{
    @Autowired
    private SundaySkuPriceService priceService;
    @RequestMapping("/index" )
    public  String price(HttpServletRequest request,
                         @RequestParam(value="skuId",required=true)Long skuId,
                         Model model){
        model.addAttribute("skuId",skuId);
        return "/sunday/sku/price/index";
    }

    @RequestMapping("/select")
    public void select(HttpServletRequest request,
                       HttpServletResponse response,
                       @RequestParam(value="skuId",required=true)Long skuId
    ) {
        try {
            PageResult<SundaySkuPrice> result=priceService.selectPrice(request,skuId);
            JsonPageUtils.renderJsonPage(result.getTotal(),result.getData(),response);
        } catch (Exception e) {
            e.printStackTrace();
            AjaxUtils.renderJsonporJson(response, null,
                    ResultPageDOHelper.getMsgCodeResultDO(CommonConstants.FAIL_CODE, CommonConstants.FAIL));
        }
    }

}
